package com.octopus.file;

import java.io.File;
import java.io.FilenameFilter;

public class CommonFileNameFilter implements FilenameFilter {
	
	private String partName;
	public static int MATCH_HEADER_ONLY = 0;
	public static int MATCH_INCLUDE_EXCEPT_HIDDEN_UNIX = 1;
	public static int MATCH_TAILER_ONLY = 2;
	public static int MATCH_INCLUDE_ANY = 3;
	public static int MATCH_FULL_EXACTLY = 4;
	public static int MATCH_REGULAR_EXP = 5;
	private int matchPattern = 0;
	
	public CommonFileNameFilter(String partName, int pattern){
		this.partName = partName;
		this.matchPattern = pattern;
	}

	public boolean accept(File dir, String name) {
		switch (matchPattern) {
		case 0: {
			if (name.indexOf(partName) == 0) {
				return true;
			} else {
				return false;
			}
		}
		case 1: {
			if (name.indexOf(partName) >= 0 && name.indexOf(".") != 0) {
				return true;
			} else {
				return false;
			}
		}
		case 2: {
			if ((name.lastIndexOf(partName) + partName.length()) == name.length() ) {
				return true;
			} else {
				return false;
			}
		}
		case 3: {
			if (name.indexOf(partName) >= 0) {
				return true;
			} else {
				return false;
			}
		}
		case 4: {
			if (name.equals(partName)) {
				return true;
			} else {
				return false;
			}
		}
		case 5: {
			if(name.matches(partName)){
				return true;
			}else{
				return false;
			}
		}
		default : return false;
		}

	}

}
